package com.btc.watcher;

import java.util.LinkedList;

/**
 *  GoxAccount keeps track of the user's account and orders on Mt. Gox
 *
 *  @author Dest
 *  @version Apr 20, 2011
 */

public class GoxAccount
{

    private String accountName;
    private String accountPass;
    private String accountUSD;
    private String accountBTC;
    private LinkedList<GoxOrder> goxOrders;

    public GoxAccount(String pName, String pPass) {
        accountName = pName;
        accountPass = pPass;
        goxOrders = new LinkedList<GoxOrder>();
    }

    public String getAccountName()
    {
        return accountName;
    }

    public void setAccountName(String accountName)
    {
        this.accountName = accountName;
    }

    public String getAccountPass()
    {
        return accountPass;
    }

    public void setAccountPass(String accountPass)
    {
        this.accountPass = accountPass;
    }

    public String getAccountUSD()
    {
        return accountUSD;
    }

    public void setAccountUSD(String accountUSD)
    {
        this.accountUSD = accountUSD;
    }

    public String getAccountBTC()
    {
        return accountBTC;
    }

    public void setAccountBTC(String accountBTC)
    {
        this.accountBTC = accountBTC;
    }

    public void addOrder(GoxOrder pOrder) {
        goxOrders.add(pOrder);
    }

    public void clearOrders() {
        goxOrders.clear();
    }

    /**
     * getOrders returns the summaries of all the orders we have
     * @return String summaries of all the orders we have
     */
    public String getOrders() {
        if(goxOrders.size() == 0) {
            return "No open orders.";
        }

        String ret = "My orders:\n\n";

        for(GoxOrder order : goxOrders) {
            ret += order.getSummary() + "\n\n";
        }

        return ret;
    }

    public LinkedList<GoxOrder> getOrderList(){
        return goxOrders;
    }
    /**
     * getOrderDetails returns all the details about a specific order
     *  *Note: we can easily do this by calling the toString of a GoxOrder
     *
     * @param pID the orderID we want to look at
     * @return String a representation of this order in string format
     */
    public String getOrderDetails(String pID) {
        if(pID == null || pID.length() == 0) {
            return "Invalid order (was either null or empty)";
        }

        for(GoxOrder order : goxOrders) {
            if((order.getOrderID()).equals(pID)) {
                return order.toString();
            }
        }

        return "Order "+pID+" was not found!";
    }
}